package com.m3958.firstgwt.server.camel;

import org.apache.camel.builder.RouteBuilder;

import com.google.inject.Inject;

public class ClonePageRouter extends RouteBuilder{

	@Inject
	private ClonePage cp;
	
	@Override
	public void configure() throws Exception {
//		from(jms.createEndpoint("TOOL.CLONE.PAGE")).bean(cp)
//		from("timer:clonepage?delay=1000&period=60s").bean(cp/*,"onMessage"*/)
		from("jpa:com.m3958.firstgwt.server.model.AsyncTask?persistenceUnit=p-unit&consumer.query=select a FROM AsyncTask AS a WHERE a.status == 'UNTOUCHED' ORDER BY a.createdAt ASC&consumeDelete=false")
		.bean(cp)
		.split().body()
		.choice()
		.when().mvel("request.body[0] == 'img'").bean(cp, "processImg")
		.when().mvel("request.body[0] == 'css'").bean(cp, "processCss").to("direct:cssimg")
		.when().mvel("request.body[0] == 'script'").bean(cp, "processScript")
		.otherwise().bean(cp, "processOthers");
    	from("direct:cssimg").split().body().bean(cp, "processImg");
		
	}

}
